$(function() {	
	$('#huodg20').datagrid({
		//请求地址
	    url:'../card/getcardDetails',
	    columns:[[
	    	{field:'',title:'',checkbox:true},
			{field:'detailsId',title:'编号',width:'8%'},
			{field:'empId',title:'员工编号',width:'8%',
				formatter: function(value,row,index){
					if (row.emp){
						return row.emp.empId;
					} else {
						return "";
					}
				}},
			{field:'cardTime',title:'签到时间',width:'15%'},
			{field:'reason',title:'原因',width:'10%'},
			{field:'whetherValid',title:'是否有效',width:'8%'}
			] ],
     onLoadSuccess : function(data) {
			$("#huo20remove").linkbutton({
				plain : true,
				iconCls : 'icon-remove'
			});
		},
		onLoadError:function(data){
			alert("加载失败")
		},
	    fit:true,
	    fitColumns:true,
	    //隔行变色
	    striped:true,
	    nowrap:true,
	    //显示行号
	    rownumbers:true,
	    //设置单选
	    singleSelect:true,
		toolbar:'#huotb20',
		//显示分页栏
		pagination:true,
		//设置每页大小
		pageSize:20,
		//可选的每页大小
		pageList:[5,10,20,50]
	});
});
 function searchname(value){
	 $('#huodg20').datagrid('load','../card/serchCheckDetails?value='+value);
} 
 var editIndex = undefined;
	function onClickCell(index, field){
		if (editIndex != index){
			if (endEditing()){
				$('#huodg20').datagrid('selectRow', index)
						.datagrid('beginEdit', index);
				var ed = $('#huodg20').datagrid('getEditor', {index:index,field:field});
				if (ed){
					($(ed.target).data('textbox') ? $(ed.target).textbox('textbox') : $(ed.target)).focus();
				}
				editIndex = index;
			} else {
				setTimeout(function(){
					$('#huodg20').datagrid('selectRow', editIndex);
				},0);
			}
		}
	}
	function removeit(){
		if (editIndex == undefined){
			var rows = $('#huodg20').datagrid('getSelections');
			if(rows.length > 0){
				$.messager.confirm('请确认','您确定要删除当前所有选中的项目吗？',function(r){
					if(r){
						var holidayIds = [];
						for(var i = 0; i < rows.length; i++){
							holidayIds.push(rows[i].detailsId)
						}
						var huo_rowData = JSON.stringify(holidayIds);
						$.ajax({
							url : "../card/deleteCheckDetails",
							data : {"jsondata" : huo_rowData},
							success : function(e) {
								if (e == "ok") {
	                               alert("删除成功");
	                               $('#huodg20').datagrid('load');
								}
							}
						});
					}
				 })
				}
		}
		$('#huodg20').datagrid('cancelEdit', editIndex).datagrid('deleteRow', editIndex);
		editIndex = undefined;
	}